package cn.wolfcode.luowowo.website.web.controller;

import cn.wolfcode.luowowo.article.domain.Destination;
import cn.wolfcode.luowowo.article.domain.StrategyDetail;
import cn.wolfcode.luowowo.article.domain.Travel;
import cn.wolfcode.luowowo.article.query.TravelQuery;
import cn.wolfcode.luowowo.article.service.*;
import cn.wolfcode.luowowo.member.domain.UserInfo;
import cn.wolfcode.luowowo.member.service.IUserService;
import cn.wolfcode.luowowo.search.service.IDestinationTemplateSearchService;
import cn.wolfcode.luowowo.search.service.IStrategyTemplateSearchService;
import cn.wolfcode.luowowo.search.service.ITravelTemplateSearchService;
import cn.wolfcode.luowowo.search.service.IUserInfoTemplateSearchService;
import cn.wolfcode.luowowo.search.template.DestinationTemplate;
import cn.wolfcode.luowowo.search.template.StrategyTemplate;
import cn.wolfcode.luowowo.search.template.TravelTemplate;
import cn.wolfcode.luowowo.search.template.UserInfoTemplate;
import cn.wolfcode.luowowo.website.annotation.UserParam;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class IndexController {

    @Reference
    private ITravelCommendService travelCommendService;

    @Reference
    private IStrategyCommendService strategyCommendService;

    @Reference
    private ITravelService travelService;

    @Reference
    private IStrategyDetailService strategyDetailService;

    @Reference
    private IStrategyTagService strategyTagService;

    @Reference
    private IDestinationService destinationService;

    @Reference
    private IUserService userService;

    @Reference
    private IStrategyTemplateSearchService strategySearchService;

    @Reference
    private IUserInfoTemplateSearchService userInfoSearchService;

    @Reference
    private ITravelTemplateSearchService travelSearchService;

    @Reference
    private IDestinationTemplateSearchService destinationSearchService;

    @RequestMapping("")
    public String index(Model model,@UserParam UserInfo userInfo){
        model.addAttribute("tcs", travelCommendService.getTop5());
        model.addAttribute("sc", strategyCommendService.getTop5().get(0));
        model.addAttribute("userInfo",userInfo);
        return "index/index";
    }

    @RequestMapping("/index/travelPage")
    public String travelPage(@ModelAttribute("qo") TravelQuery qo,Model model){
        qo.setPageSize(10);
        model.addAttribute("pageInfo",travelService.query(qo));
        return "index/travelPageTpl";
    }


    @RequestMapping("/getUser")
    @ResponseBody
    public UserInfo getUser(@UserParam UserInfo userInfo){
        return userInfo;
    }
}
